var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        //管理员信息
        manager_id: null,
        manager_name: null,
        manager_avatar: null,
        //成员列表
        member_info_list: [],
        isManager: false
    },

    goToUser: function(event) {
        wx.navigateTo({
            url: '/pages/userinfo/userinfo?uid=' + event.currentTarget.dataset.uid
        });
    },

    deleteMember: function(event) {
        var that = this;
        app.alert({
            "content": "确定要删除该用户吗",
            "showCancel": true,
            // 点击确定执行
            "cb_confirm": function() {
                var user_id = event.currentTarget.dataset.uid;
                wx.request({
                    url: app.buildUrl('/group/remove-member'),
                    header: app.getRequestHeader(),
                    data: {
                        user_id: user_id,
                        group_id: that.data.group_id
                    },
                    success: function(res) {
                        var resp = res.data;
                        app.alert({
                            "content": resp.msg
                        });
                        if (resp.code == 200) that.getGroupInfo();
                    }
                })
            },
        })
        
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({ 'group_id': parseInt(options.gid) });
        this.setData({ 'isManager': Boolean(options.isManager) });
        this.getGroupInfo();
    },

    getGroupInfo: function () {
        var that = this;
        wx.request({
            url: app.buildUrl("/group/info"),
            header: app.getRequestHeader(),
            data: {
                "group_id": this.data.group_id
            },
            success: function (res) {
                var resp = res.data;
                if (resp.code != 200) {
                    app.alert({
                        "content": resp.msg
                    });
                    return;
                }
                var group_info = resp.data.group_info;
                that.setData({
                    manager_id: group_info.manager_id,
                    manager_name: group_info.manager_name,
                    manager_avatar: group_info.manager_avatar,
                    member_info_list: resp.data.member_info_list
                });
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})